Add a warning when packaging crates with wildcard dependencies
authorSteven Fackler <sfackler@gmail.com>
Sun, 27 Sep 2015 23:52:01 +0000 (16:52 -0700)
committerFlorian Hahn <flo@fhahn.com>
Wed, 30 Sep 2015 19:30:52 +0000 (21:30 +0200)
src/cargo/ops/cargo_package.rs

index cf0bd9d831bf3afa4186393928bc7d0113666715..64fc7e2ea573a399f8180faa1474d32a81878a1f 100644 (file)
@@ -2,11 +2,13 @@ use std::io::prelude::*;
 use std::fs::{self, File};
 use std::path::{self, Path, PathBuf};
 
+use semver::VersionReq;
 use tar::Archive;
 use flate2::{GzBuilder, Compression};
 use flate2::read::GzDecoder;
 
 use core::{SourceId, Package, PackageId};
+use core::dependency::Kind;
 use sources::PathSource;
 use util::{self, CargoResult, human, internal, ChainError, Config};
 use ops;
@@ -35,6 +37,8 @@ pub fn package(manifest_path: &Path,
         try!(check_metadata(&pkg, config));
     }
 
+    try!(check_dependencies(&pkg, config));
+
     if list {
         let root = pkg.root();
         let mut list: Vec<_> = try!(src.list_files(&pkg)).iter().map(|file| {
@@ -102,6 +106,32 @@ fn check_metadata(pkg: &Package, config: &Config) -> CargoResult<()> {
     Ok(())
 }
 
+// Warn about wildcard deps which will soon be prohibited on crates.io
+#[allow(deprecated)] // connect => join in 1.3
+fn check_dependencies(pkg: &Package, config: &Config) -> CargoResult<()> {
+    let wildcard = VersionReq::parse("*").unwrap();
+
+    let mut wildcard_deps = vec![];
+    for dep in pkg.dependencies() {
+        if dep.kind() != Kind::Development && dep.version_req() == &wildcard {
+            wildcard_deps.push(dep.name());
+        }
+    }
+
+    if !wildcard_deps.is_empty() {
+        let deps = wildcard_deps.connect(", ");
+        try!(config.shell().warn(
+            "warning: some dependencies have wildcard (\"*\") version constraints. \
+             On December 11th, 2015, crates.io will begin rejecting packages with \
+             wildcard dependency constraints. See \
+             http://doc.crates.io/crates-io.html#using-crates.io-based-crates \
+             for information on version constraints."));
+        try!(config.shell().warn(
+            &format!("dependencies for these crates have wildcard constraints: {}", deps)));
+    }
+    Ok(())
+}
+
 fn tar(pkg: &Package, src: &PathSource, config: &Config,
        dst: &Path) -> CargoResult<()> {